home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / Acere (PowerPlant, Game) 1.2 / AcereÄ.sit / Acereƒ / Code / WellDeck.cp < prev    next >
Text File  |  1995-02-16  |  4KB  |  159 lines

  1. // ===========================================================================
  2. //    WellDeck.cp                        ⌐1993 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    Class for an object that can draw itself and respond to mouse clicks
  6.  
  7. #ifdef PowerPlant_PCH
  8. #include PowerPlant_PCH
  9. #endif
  10.  
  11. #include "WellDeck.h"
  12. #include "CardDeck.h"
  13. #include "AcereApp.h"
  14. #include "CTextDoc.h"
  15. #include <LDynamicArray.h>
  16. #include <LView.h>
  17. #include <LStream.h>
  18. #include <PP_Messages.h>
  19. #include <UDrawingState.h>
  20.  
  21. extern    CTextDoc    *theDoc;
  22. extern    unsigned long     ourAvailRam;
  23.  
  24. // ---------------------------------------------------------------------------
  25. //        Ñ CreatePaneStream [static]
  26. // ---------------------------------------------------------------------------
  27. //    Return a new Pane object initialized using data from a Stream
  28.  
  29. WellDeck*
  30. WellDeck::CreateWellDeck(
  31.     LStream    *inStream)
  32. {
  33.     return (new WellDeck(inStream));
  34. }
  35.  
  36.  
  37. // ---------------------------------------------------------------------------
  38. //        Ñ WellDeck()
  39. // ---------------------------------------------------------------------------
  40. //    Default Constructor
  41.  
  42. WellDeck::WellDeck() : CardWell()
  43. {
  44.     InitCard();
  45. }
  46.  
  47.  
  48. // ---------------------------------------------------------------------------
  49. //        Ñ WellDeck(const WellDeck&)
  50. // ---------------------------------------------------------------------------
  51. //    Copy Constructor
  52.  
  53. WellDeck::WellDeck(
  54.     const WellDeck    &inOriginal) : CardWell(inOriginal)
  55. {
  56.                                     // Copy members of Original
  57.     InitCard();
  58. }
  59.  
  60.  
  61. // ---------------------------------------------------------------------------
  62. //        Ñ WellDeck(SPaneInfo&)
  63. // ---------------------------------------------------------------------------
  64. //    Construct Pane from data in a struct
  65.  
  66. WellDeck::WellDeck(const SPaneInfo    &inPaneInfo) : CardWell(inPaneInfo)
  67. {
  68.     InitCard();
  69. }
  70.  
  71.  
  72. // ---------------------------------------------------------------------------
  73. //        Ñ WellDeck(LStream*)
  74. // ---------------------------------------------------------------------------
  75. //    Construct Pane from data in a Stream
  76.  
  77. WellDeck::WellDeck(
  78.     LStream    *inStream) : CardWell(inStream)
  79. {
  80.     InitCard();
  81. }
  82.  
  83.  
  84. // ---------------------------------------------------------------------------
  85. //        Ñ InitPane
  86. // ---------------------------------------------------------------------------
  87. //    Initialize Pane from data in a struct
  88.  
  89. void
  90. WellDeck::InitCard(void)
  91. {
  92. //    CardWell::InitPane(inPaneInfo);    
  93.     
  94.     theDoc->theDeckWells[theDoc->currentDeckWell] = this;
  95.     theDoc->currentDeckWell++;
  96.  
  97. //    itsCard = nil;
  98. }
  99.  
  100.  
  101. // ---------------------------------------------------------------------------
  102. //        Ñ ~WellDeck
  103. // ---------------------------------------------------------------------------
  104. //    Destructor
  105.  
  106. WellDeck::~WellDeck()
  107. {
  108.     PutInside(nil);
  109.     
  110.     if (sLastPaneClicked == this) {
  111.         sLastPaneClicked = nil;
  112.     }
  113. }
  114.  
  115.  
  116. Boolean    WellDeck::CanDropOnEmptySlot(PlayingCard *draggedCard)
  117. {
  118.     //    this will be overridden by most subclasses, which is why it's separate
  119.     //    default behavior is that ANY card can be dropped on an empty slot
  120.     
  121.     if (draggedCard->card == 1)        //    it's an ACE
  122.         return (true);
  123.     else
  124.         return (false);
  125. }
  126.  
  127. Boolean    WellDeck::CanDropOnSlot(PlayingCard *draggedCard)
  128. {
  129.     //    this will be overridden by most subclasses.
  130.     //    default behavior is that any card can be dropped on any card.
  131.  
  132.     if ((draggedCard->suit == itsCard->suit) &&
  133.             (draggedCard->card == (itsCard->card +1)))
  134.         return (true);
  135.     else
  136.         return (false);
  137. }
  138.  
  139. Boolean    WellDeck::CanRemove(void)            //    can we remove cards from this pile?
  140. {
  141.     return (false);
  142. }
  143.  
  144. void WellDeck::AddCardToWell(CardWell *whichWell, PlayingCard *whichCard)
  145. {
  146.     CardWell *itsOwner = whichCard->itsOwner;
  147.     PlayingCard *oldCard = itsCard;
  148.     
  149.     CardWell::AddCardToWell(whichWell, whichCard);
  150.     
  151.     if (oldCard != nil)
  152.         delete oldCard;                        //    fixes memory leak from cards "disappearing"
  153.     
  154.     itsOwner->DrawSelf();
  155.     
  156.     if (whichCard->card == 13)                //    it's a King
  157.         theDoc->CheckVictory();
  158. }
  159.